package hoodoos.example.java;

import hoodoos.rule.api.Facts;
import hoodoos.rule.api.GlobalContext;
import hoodoos.rule.api.RequestContext;
import hoodoos.rule.core.BasicRule;
import hoodoos.rule.script.java.PureRule;

@PureRule("RuleA")
public class RuleA extends BasicRule {

  public RuleA(String name) {
    super(name);
  }

  @Override
  public boolean evaluate(GlobalContext globalContext, RequestContext requestContext) {
    return true;
  }

  @Override
  public void execute(GlobalContext globalContext, RequestContext requestContext, Facts facts) {
    Integer aCardScore = requestContext.getIntRequestParameter("a_card_score");
    Integer bCardScore = requestContext.getIntRequestParameter("b_card_score");
    String pd_living_province = requestContext.getStrRequestParameter("pd_living_province");
    String pd_census_province = requestContext.getStrRequestParameter("pd_census_province");

    boolean isRefuse = aCardScore > 100
        && bCardScore < 450
        && !pd_living_province.contains("乌克兰")
        && pd_census_province.contains("吉尔吉斯斯坦");

    facts.setRefuse(isRefuse);
  }
}
